package services.impl;

import java.sql.SQLException;
import java.util.List;

import dao.OrderDao;
import dao.impl.OrderDaoImpl;
import entity.OrderDetails;
import services.OrderService;

public class OrderServiceImpl implements OrderService{
	OrderDao oDao = null;
	public OrderServiceImpl() {
		oDao = new OrderDaoImpl();
	}
	/*
	 * 创建订单
	 */
	@Override
	public int CreateOrder(int user_id,int goods_id) {
		int res = 0;
		try {
			res = oDao.insertOrder(user_id, goods_id);
			if(res > 0) return res;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return res;
	}
	/*
	 * 查询所有订单
	 */
	@Override
	public List<OrderDetails> getOrderByid(int user_id) {
		List<OrderDetails> orderList = null;
		try {
			orderList = oDao.getAllOrderByid(user_id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return orderList;
	}
	/**
	 * 修改订单状态
	 */
	@Override
	public int updateOrderStatus(int user_id, int order_id) {
		int res = 0;
		try {
			res = oDao.updateStatus(OrderDetails.HADPAY, order_id);
			if(res > 0) return res;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return res;
	}

}
